package com.boot.result;

import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    public Result() {
    }


    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>();
        result.code = 1;  //1是成功
        result.msg = "success";
        result.data = data;
        return result;
    }

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 1;  //1是成功
        result.msg = "success";
        return result;
    }

    public static <T> Result<T> build(T data, ResultCodeNum resultCodeNum) {
        Result<T> result = new Result<T>();
        result.code = resultCodeNum.getCode();
        result.msg = resultCodeNum.getMsg();
        result.data = data;
        return result;
    }

    public static <T> Result<T> build(T data, int code, String msg) {
        Result<T> result = new Result<T>();
        result.code = code;
        result.msg = msg;
        result.data = data;
        return result;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
